#include "proj_config.h"
#include "osal/osal.h"
#include "usr_app.h"
#include "hal/hal_interrupt.h"
#include "ln_kv_api.h"
#include "flash_partition_table.h"

#include "utils/debug/log.h"
#include "utils/runtime/runtime.h"
#include "utils/reboot_trace/reboot_trace.h"
#include "utils/debug/CmBacktrace/cm_backtrace.h"


int main (int argc, char* argv[])
{
    //0. check reboot cause
    ln_chip_get_reboot_cause();

    //1.sys clock,interrupt
    SetSysClock();
    set_interrupt_priority();
    switch_global_interrupt(true);
    ln_runtime_measure_init();

    //2. register os heap mem
    OS_DefineHeapRegions();

    //3.init log
    log_init();

    cm_backtrace_init("mcu_rtos_demo", "HW_V1.0", "SW_V1.0");
    LOG(LOG_LVL_INFO, "------  mcu_rtos_demo  ------\r\n");

    if (KV_ERR_NONE != ln_kv_port_init(KV_SPACE_OFFSET, (KV_SPACE_OFFSET + KV_SPACE_SIZE))) {
        LOG(LOG_LVL_ERROR, "KV init filed!\r\n");
    }

    //Creat usr app task.
    creat_usr_app_task();

    OS_ThreadStartScheduler();

    return 0;
}

// ----------------------------------------------------------------------------
